package com.ruoyi.system.Fdongbei.service.impl;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.system.Fdongbei.domain.TbMenjin;
import com.ruoyi.system.Fdongbei.domain.dibang.GuozhongDo;
import com.ruoyi.system.Fdongbei.domain.dibang.MenjinDo;
import com.ruoyi.system.Fdongbei.mapper.TbMenjinMapper;
import com.ruoyi.system.Fdongbei.mapper.dibang.GuozhongDoMapper;
import com.ruoyi.system.Fdongbei.mapper.dibang.MenjinDoMapper;
import com.ruoyi.system.Fdongbei.service.ITbMenjinService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.StringReader;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author fufeng
 * @since 2024-12-05
 */
@Service
public class TbMenjinServiceImpl implements ITbMenjinService {

    @Resource
    private MenjinDoMapper menjinDoMapper;
    @Resource
    private GuozhongDoMapper guozhongDoMapper;


    @Resource
    TbMenjinMapper tbMenjinMapper;


    @Override
    @DataSource(value = DataSourceType.LY002_D)
    public AjaxResult menjinModifyStatus(String czbh) {

        GuozhongDo guozhongDo = guozhongDoMapper.selectByPrimaryKey(czbh);
        MenjinDo menjinDo = menjinDoMapper.selectByCzbh(czbh);

        if (guozhongDo == null) {
            return AjaxResult.error("没有车辆信息");
        }

        if (!guozhongDo.getGbzt().equals("完成")) {
            return AjaxResult.error("车辆未完成过磅");
        }

        String cczt = menjinDo.getCczt();
        if (cczt == null) {
            cczt = "出厂";
            menjinDo.setCczt(cczt);
            int i = menjinDoMapper.updateMenjinStatuxByCzbh(menjinDo);
            if (i > 0) {
                return AjaxResult.success("修改成功");
            }
        } else {
            cczt = null;
            menjinDo.setCczt(cczt);
            int i = menjinDoMapper.updateMenjinStatuxByCzbh(menjinDo);
            if (i > 0) {
                return AjaxResult.success("修改成功");
            }
        }

        return AjaxResult.error("修改失败");

    }


    @DataSource(value = DataSourceType.LY002_D)
    public int deletemenjinbyczbh(String czbh) {
        return tbMenjinMapper.deletemenjinbyczbh(czbh);
    }


}
